package handler

import (
	"car-trade-mgr/model"
	"github.com/gin-gonic/gin"
)

func CarAdd(c *gin.Context) {
	carName := c.PostForm("car_name")
	carType := c.PostForm("car_type")
	carPrice := c.PostForm("car_price")
	carNum := c.PostForm("car_num")
	carTime := c.PostForm("car_time")
	data := model.Car{
		CarName:  carName,
		CarType:  carType,
		CarPrice: carPrice,
		CarNum:   carNum,
		CarTime:  carTime,
	}
	err := model.DB.Create(&data).Debug().Error
	if err != nil {
		c.JSON(200, gin.H{
			"code": 500,
			"msg":  "添加失败",
		})
		return
	}
	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "添加成功",
	})
	return
}
